package company.baidu;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class BD1 {

    static List<String> list = new ArrayList<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int[] used = new int[n];
        for (int i = 0; i < n; i++) {
            if (array[i] != 0)
                helper(array, used, 1, n, String.valueOf(i));
        }
        System.out.println(list);
    }

    private static void helper(int[] array, int[] used, int step, int n, String s) {
        if (step == n) {
            if (Long.parseLong(s) % 90 == 0)
                list.add(s);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (used[i] == 0) {
                used[i] = 1;
                helper(array, used, step + 1, n, s + array[i]);
                used[i] = 0;
            }
        }
    }
}
